/**
 * @file     board.h
 * @author   AE TEAM
 * @brief    This file provides all the functions prototypes for the board level support package.
 *
 * @attention
 *
 * THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
 * CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
 * TIME. THEREFORE, METANERGY SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
 * CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
 * HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
 * CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
 *
 * <H2><CENTER>&COPY; COPYRIGHT METANERGY </CENTER></H2>
 */

/** Define to prevent recursive inclusion */
#ifndef __BOARD_H
#define __BOARD_H

/** Files includes */
#include <stdio.h>
#include "myg0025_def.h"
#include "myg0025_rcc.h"
#include "myg0025_gpio.h"
#include "myg0025_comp.h"
#include "drv_inc.h"

/* Board name */
//0002G40 Demo board

/** Interrupt priorities */
/**
 * The order of priority decreases from small to large
 * 0 : highest priority-first
 */
#define SYSTICK_INTERRUPT           (2)              //Unchangeable
#define TIM1_INTERRUPT              (0)              //Unchangeable
#define ADC1_INTERRUPT              (1)              //Unchangeable
#define TIM3_UPDATE_INTERRUPT       (3)              //Unchangeable

/** ADC interface */

#define IU_CH_BUFFER                (0)              //Unchangeable
#define IV_CH_BUFFER                (1)              //Unchangeable
#define VBUS_CH_BUFFER              (2)              //Unchangeable
#define VSP_CH_BUFFER               (3)              //Unchangeable

#define AIN0                        VBUS_CH_BUFFER
#define AIN11                       IV_CH_BUFFER
#define AIN9                        VSP_CH_BUFFER
#define AIN12                       IU_CH_BUFFER

#define ADC_GPIO_CLK               (RCC_AHBPeriph_GPIOA)
#define VR_PORT                     GPIOA
#define VR_PIN                      GPIO_Pin_0

#define VBUS_PORT                   GPIOA
#define VBUS_PIN                    GPIO_Pin_2

#define IR_U_PORT                   //GPIOD
#define IR_U_PIN                    //GPIO_Pin_2

#define IR_V_PORT                   //GPIOC
#define IR_V_PIN                    //GPIO_Pin_4

#define VR_PIN_SRC                  GPIO_PinSource3
#define VBUS_PIN_SRC                GPIO_PinSource6
#define IR_U_PIN_SRC                //GPIO_PinSource2
#define IR_V_PIN_SRC                //GPIO_PinSource4

#define VR_PIN_AF                   GPIO_AF_7
#define VBUS_PIN_AF                 GPIO_AF_7
#define IR_U_PIN_AF                 //GPIO_AF_7
#define IR_V_PIN_AF                 //GPIO_AF_7

/** LED interface */
//#define LED_RCC_CLOCKGPIO           (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOA)

//#define LED1_PORT                   GPIOD
//#define LED1_PIN                    GPIO_Pin_3

//#define LED2_PORT                   GPIOC
//#define LED2_PIN                    GPIO_Pin_5

//#define LED1_ON()                   LED1_PORT->BRR = LED1_PIN
//#define LED1_OFF()                  LED1_PORT->BSRR = LED1_PIN
//#define LED2_ON()                   LED2_PORT->BRR = LED2_PIN
//#define LED2_OFF()                  LED2_PORT->BSRR = LED2_PIN
//#define LED1_TOGGLE()               LED1_PORT->ODR ^= LED1_PIN
//#define LED2_TOGGLE()               LED2_PORT->ODR ^= LED2_PIN

/** PWM interface */

#define BLDC_GPIO_CLK               (RCC_AHBPeriph_GPIOB)

#define BLDC_UH_PORT                GPIOB
#define BLDC_UH_PIN                 GPIO_Pin_12
#define BLDC_VH_PORT                GPIOB
#define BLDC_VH_PIN                 GPIO_Pin_11
#define BLDC_WH_PORT                GPIOB
#define BLDC_WH_PIN                 GPIO_Pin_10

#define BLDC_UL_PORT                GPIOB
#define BLDC_UL_PIN                 GPIO_Pin_6
#define BLDC_VL_PORT                GPIOB
#define BLDC_VL_PIN                 GPIO_Pin_4
#define BLDC_WL_PORT                GPIOB
#define BLDC_WL_PIN                 GPIO_Pin_7

//#define BLDC_BKP_PORT               GPIOA
//#define BLDC_BKP_PIN                GPIO_Pin_6

#define BLDC_UH_PIN_SRC             GPIO_PinSource12
#define BLDC_VH_PIN_SRC             GPIO_PinSource11
#define BLDC_WH_PIN_SRC             GPIO_PinSource10
#define BLDC_UL_PIN_SRC             GPIO_PinSource6
#define BLDC_VL_PIN_SRC             GPIO_PinSource4
#define BLDC_WL_PIN_SRC             GPIO_PinSource7
//#define BLDC_BKP_PIN_SRC            GPIO_PinSource6

#define BLDC_UH_PIN_AF              GPIO_AF_2
#define BLDC_VH_PIN_AF              GPIO_AF_2
#define BLDC_WH_PIN_AF              GPIO_AF_2
#define BLDC_UL_PIN_AF              GPIO_AF_2
#define BLDC_VL_PIN_AF              GPIO_AF_2
#define BLDC_WL_PIN_AF              GPIO_AF_3
//#define BLDC_BKP_PIN_AF             GPIO_AF_3

/** User interface */
#define FG_IO_PORT                  GPIOC
#define FG_IO_PIN                   GPIO_Pin_2

#define PWMIN_IO_PORT               GPIOC
#define PWMIN_IO_PIN                GPIO_Pin_3
#define PWMIN_IO_PIN_AF             GPIO_AF_4
#define PWMIN_IO_PIN_SRC            GPIO_PinSource3


//GPIO, FG
//#define PC6_1                       (GPIOC->BSRR|= GPIO_Pin_6)
//#define PC6_0                       (GPIOC->BRR |= GPIO_Pin_6)
//#define PC6_TOGGLE()                (GPIOC ->ODR ^= GPIO_Pin_6)
#define PC3_1                       (GPIOC->BSRR|= GPIO_Pin_3)
#define PC3_0                       (GPIOC->BRR |= GPIO_Pin_3)
#define PC3_TOGGLE()                (GPIOC ->ODR ^= GPIO_Pin_3)


//GPIO, PWM
#define PC4_1                       (GPIOC->BSRR|= GPIO_Pin_4)
#define PC4_0                       (GPIOC->BRR |= GPIO_Pin_4)
#define PC4_TOGGLE()                (GPIOC ->ODR ^= GPIO_Pin_4)

/**
 * @addtogroup MYg0002_Hardware_Driver_Layer
 * @{
 */

/**
 * @addtogroup Bsp
 * @{
 */


extern void Bsp_Gpio_Init(void);
extern void Peripheral_Init(void);
/**
  * @}
*/

/**
  * @}
*/


#endif
